cmake_minimum_required(VERSION 2.8)
project(PagedGeometry)

INCLUDE(CheckCCompilerFlag)

# some optimization flags
if(WIN32)
    set(CMAKE_CXX_FLAGS_RELEASE        "${CMAKE_CXX_FLAGS_RELEASE}        /MP /GL /Ox /Ob2 /Oi /Ot /Oy /fp:fast /GS- /MP /Zi")
    set(CMAKE_CXX_FLAGS_MINSIZEREL     "${CMAKE_CXX_FLAGS_MINSIZEREL}     /MP /Zi")
    set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MP /Od /Zi")
    set(CMAKE_CXX_FLAGS_DEBUG          "${CMAKE_CXX_FLAGS_DEBUG}          /MP /Od /Zi")
    # some general flags add_definitions("-D_CRT_SECURE_NO_WARNINGS")

    set(CMAKE_EXE_LINKER_FLAGS_DEBUG          "${CMAKE_EXE_LINKER_FLAGS_DEBUG}          /DEBUG /SUBSYSTEM:WINDOWS")
    set(CMAKE_EXE_LINKER_FLAGS_RELEASE        "${CMAKE_EXE_LINKER_FLAGS_RELEASE}        /DEBUG /SUBSYSTEM:WINDOWS /LTCG /OPT:REF")
    set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL     "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}     /DEBUG /SUBSYSTEM:WINDOWS /LTCG /OPT:REF")
    set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /DEBUG /SUBSYSTEM:WINDOWS /LTCG /OPT:REF")
ELSEIF(UNIX)
    set(CMAKE_EXE_LINKER_FLAGS_RELEASE      "${CMAKE_EXE_LINKER_FLAGS_RELEASE}      -mfpmath=sse -msse2 -mmmx -msse -msse3 -m3dnow -O2 -fomit-frame-pointer -fstrict-aliasing -ffast-math -ftracer")
    set(CMAKE_EXE_LINKER_FLAGS_RelWithDebug "${CMAKE_EXE_LINKER_FLAGS_RelWithDebug} -O0")
endif(WIN32)

# some PG build options
set(PAGEDGEOMETRY_DYNAMIC_LIBS "FALSE" CACHE BOOL "build dynamic instead of static libraries")
set(PAGEDGEOMETRY_ALTERNATE_COORDSYSTEM "FALSE" CACHE BOOL "alternate coordinate system, do not use unless you are very sure about it")
set(PAGEDGEOMETRY_USE_OGRE_RANDOM       "FALSE" CACHE BOOL "fallback to Ogre's PRNG instead of using our own (not recommended)")
set(PAGEDGEOMETRY_USER_DATA             "FALSE" CACHE BOOL "ability to attach user data to entities")

# some versioning things
SET(LIB_MAJOR_VERSION "1")
SET(LIB_MINOR_VERSION "1")
SET(LIB_BUILD_VERSION "4")
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")

CONFIGURE_FILE(
    "include/PagedGeometryConfig.h.in"
    "PagedGeometryConfig.h")

# Set visibility options if available
IF(NOT WIN32)
	CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
	IF(HAVE_VISIBILITY_SWITCH)
		CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
									int main() {return 0;}" HAVE_GCC_VISIBILITY)
		IF(HAVE_GCC_VISIBILITY)
			ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
		ENDIF()
	ENDIF()
ENDIF()

include_directories(include)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${Ogre_INCLUDE_DIRS})

FILE(GLOB sources source/*.cpp include/*.h)

ADD_LIBRARY(PagedGeometry STATIC ${sources})
